package com.todod.common.util;

import java.util.Base64;
import java.util.Map;
import java.util.Set;

import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;

public class RestTemplatUtil {

	public static HttpEntity<String> getHeader(String requestParam, Map<String, String> headers) {
		HttpHeaders httpHeaders = new HttpHeaders();
		if (headers != null) {
			Set<String> keySet = headers.keySet();
			for (String key : keySet) {
				httpHeaders.add(key, headers.get(key));
			}
		}

		// 请求体
		// 封装成一个请求对象
		HttpEntity<String> entity = new HttpEntity<String>(requestParam, httpHeaders);

		return entity;
	}

	public static String getAuthorization(String author) {
		byte[] auth = Base64.getEncoder().encode(author.getBytes());
		String sauth = new String(auth);

		return "Basic " + sauth;
	}

}
